import pandas as pd
import numpy as np
from sklearn.preprocessing import MinMaxScaler,StandardScaler,LabelEncoder,KBinsDiscretizer
from sklearn.impute import SimpleImputer
from scipy import stats
from numpy import nan as NA
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import json as json
import seaborn as sns
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
from xgboost import XGBRegressor as XGBR
from xgboost import XGBRFClassifier as XGBC
from sklearn.ensemble import RandomForestRegressor as RFR
from sklearn.linear_model import LinearRegression as LinearR
from sklearn.model_selection import KFold, cross_val_score as CVS, train_test_split as TTS
from sklearn.metrics import mean_squared_error as MSE
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
import datetime
from lightgbm import LGBMRegressor as LGBR
from lightgbm import LGBMClassifier as LGBC
from sklearn.metrics import mean_squared_error as MSE
from sklearn.model_selection import GridSearchCV
from sklearn.preprocessing import MinMaxScaler,StandardScaler,LabelEncoder,KBinsDiscretizer
from sklearn.impute import SimpleImputer
import pandas as pd
from mlxtend.frequent_patterns import apriori
from mlxtend.frequent_patterns import association_rules
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.metrics import confusion_matrix, classification_report
import shap
from matplotlib import pyplot as plt
from pdpbox import pdp, get_dataset, info_plots
from sklearn.metrics import roc_curve, auc



data2 = pd.read_excel(r'b222.xlsx')
x = data2.iloc[:,5:]
y = data2.iloc[:,3]

X_train, X_test, y_train, y_test = TTS(x, y, test_size=0.2, stratify=y, random_state=0)
print(X_train.shape, X_test.shape, y_train.shape, y_test.shape)



from imblearn.over_sampling import SMOTE



print("Before OverSampling, counts of label\n{}".format(y_train.value_counts()))

smote = SMOTE()
x_train_res, y_train_res = smote.fit_resample(X_train, y_train)



print("After OverSampling, counts of label\n{}".format(y_train_res.value_counts()))
df = pd.concat([x_train_res,pd.DataFrame(y_train_res)],axis=1)#新特征矩阵
df.to_excel(r'C:\Users\86139\Desktop\训练数据.xlsx')
df = pd.concat([X_test,pd.DataFrame(y_test)],axis=1)#新特征矩阵
df.to_excel(r'C:\Users\86139\Desktop\测试数据.xlsx')